package com.atm.service;

import com.atm.entity.CashLog;
import com.atm.entity.DepositLog;
import com.atm.entity.TransferLog;
import com.atm.mapper.CashLogMapper;
import com.atm.mapper.DepositLogMapper;
import com.atm.mapper.TransferLogMapper;
import com.atm.utils.result.Result;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class LogService {

    @Resource
    private CashLogMapper cashLogMapper;
    @Resource
    private DepositLogMapper depositLogMapper;
    @Resource
    private TransferLogMapper transferLogMapper;

    public Result<List<CashLog>> showCashLog(String accountNo) {
        Wrapper<CashLog> wrapper = new QueryWrapper<CashLog>().eq("accountNo", accountNo);
        List<CashLog> res = cashLogMapper.selectList(wrapper);
        if(res==null)
            return Result.fail("记录为空");

        return Result.ok(res);
    }

    public Result<List<DepositLog>> showDepositLog(String accountNo) {
        Wrapper<DepositLog> wrapper = new QueryWrapper<DepositLog>().eq("accountNo", accountNo);
        List<DepositLog> res = depositLogMapper.selectList(wrapper);
        if(res==null)
            return Result.fail("记录为空");

        return Result.ok(res);
    }

    public Result<List<TransferLog>> showTransferLog(String accountNo) {
        Wrapper<TransferLog> wrapper = new QueryWrapper<TransferLog>().eq("fromAccountId", accountNo);
        List<TransferLog> res = transferLogMapper.selectList(wrapper);
        if(res==null)
            return Result.fail("记录为空");

        return Result.ok(res);
    }
}
